package com.exp.controller;

import com.exp.dao.AdminMapper;
import com.exp.dao.TopMapper;
import com.exp.model.Admin;
import com.exp.model.Top;
import com.exp.service.AdminService;
import com.exp.service.TopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 Created by guojianyu on 2016/1/24.
 */
@Controller
@RequestMapping("/top")
public class TopController {
    @Autowired
    private TopService topService;
    /*页面*/
    @RequestMapping("/view")
    public String view() {
        return "top/topList";
    }
    /*获取列表*/
    @RequestMapping("/list")
    @ResponseBody
    public List<Top> list(@RequestParam Map<String, Object> params) {
        List<Top> top = topService.getList(params);
        return top;
    }
    /*删除*/
    @RequestMapping("/delete/{id}")
    @ResponseBody
    public boolean delete(@PathVariable Integer id) {
        topService.delete(id);
        return true;
    }
    /*增加修改*/
    @RequestMapping("/edit")
    @ResponseBody
    public boolean edit(Top top) {
        try {
            if (top.getId() != null) {
                topService.update(top);
            } else {
                topService.add(top);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
